package com.example.snake;

import java.awt.*;
import java.util.Objects;

/**
 * 节点类：保存坐标 x.y
 */
public class Node {
    private int x;
    private int y;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Node() {
    }

    public Node(int x, int y) {
        this.x = x;
        this.y = y;
    }

    //绘制蛇的方法
    public void drawNode(Graphics g, int i) {
        //区分头和身体
        // 头索引0，绘制圆
        //不是头索引不为0，绘制矩形
        if (i == 0) {
            g.fillOval(this.x, this.y, 20 - 1, 20 - 1);
        } else {
            g.fillRect(this.x, this.y, 20 - 1, 20 - 1);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node node = (Node) o;
        return x == node.x && y == node.y;
    }


}
